<template>
	<view class="page pageBg" :style="{ backgroundImage: `url(${staticBg}listBj.png)`}">
		<headnav leftText="订单详情"></headnav>
		<scroll-view scroll-y="true"  class="scroll-v pageScroll">
		    <view class="pageBox">
				<view class="status block">
					<text>{{model.show_status_str}}</text>
				</view>
				<view class="d-dls" v-if="model.after_sale_status == 0">
					<view class="dl">
						<view class="dt">公司信息{{model.show_status}}</view>
						<view class="dd" v-if="model.store">{{model.store.name}}</view>
					</view>
					<view class="dl">
						<view class="dt">配送方式</view>
						<view class="dd" v-if="model.delivery_type_str">{{model.delivery_type_str}}</view>
					</view>
					<view class="dl">
						<view class="dt">学生姓名</view>
						<view class="dd" v-if="model.consignee_name">{{model.consignee_name}}</view>
					</view>
					<view class="dl">
						<view class="dt">学生手机号</view>
						<view class="dd" v-if="model.consignee_phone">{{model.consignee_phone}}</view>
					</view>
				</view>
				<view class="d-dls" v-if="model.after_sale_status == 0">
					<view class="dl">
						<view class="dt">学校</view>
						<view class="dd" v-if="user.school_name">{{user.school_name}}</view>
					</view>
					<view class="dl">
						<view class="dt">学院</view>
						<view class="dd" v-if="user.school_name">{{user.school_college_name}}</view>
					</view>
					<view class="dl">
						<view class="dt">专业</view>
						<view class="dd" v-if="user.school_profession_name">{{user.school_profession_name}}</view>
					</view>
					<view class="dl">
						<view class="dt">班级</view>
						<view class="dd" v-if="user.class_name">{{user.class_name}}</view>
					</view>
				</view>
				<goodsItem :model='model' :goods="goods" :order_status='order_status' :is_pre='is_pre'></goodsItem>
				<view class="dlsleft">
					<view class="dl" v-if="model.no">
						订单编号：{{model.no}}
					</view>
					<view class="dl" v-if="model.show_status_str">
						订单状态：{{model.show_status_str}}
					</view>
					<view class="dl" v-if="model.created_at">
						下单时间：{{model.created_at}}
					</view>
					<view class="dl" v-if="model.pay_at">
						<text v-if="is_pre == 0">付款时间：</text>
						<text v-if="is_pre == 1">预付款时间：</text>
						{{model.pay_at}}
					</view>
					<view class="dl" v-if="model.balance_payment_time">
						支付尾款时间：{{getTime(model.balance_payment_time)}}
					</view>
					<view class="dl" v-if="model.shipped_at">
						发货时间：{{model.shipped_at}}
					</view>
					<view class="dl" v-if="model.received_at">
						收货时间：{{model.received_at}}
					</view>
				</view>
			<!-- 	<view class="bottomBtn">
					<view class="bt bt-a">重新申请</view>
				</view> -->
			</view>
		</scroll-view>
	<!-- 	<view class="totelBotttom">
			<view class="btnBox">
				<view class="d-btn">取消订单</view>
				<view class="d-btn btn-a">立即支付</view>
			</view>
		</view> -->
		<view class="totelBotttom" v-if="model.btn && model.btn.length > 1">
			<view class="rightWrap">
				<view class="o-btn" :class="{active:item.k == 2 || item.k == 5}" @tap="btnEVent(item.k,model)" v-for="(item,index) in model.btn" v-if="item.k != 1 && item.k != 8" :key="index">{{item.v}}</view>
			</view>
		</view>	
	</view>
</template>
<!-- const BTN_PAY = 2;
    const BTN_CANCEL = 3;
    const BTN_REFUND = 4;
    const BTN_RECEIPT = 5;
    const BTN_FINISH = 6;
    const BTN_DELETE = 7;
    const BTN_CUSTOMER = 8;
    const BTN_REMAINING = 9;
    const BTN_LIST = [
        self::BTN_VIEW => '详情',
        self::BTN_PAY => '去支付',
        self::BTN_CANCEL => '取消订单',
        self::BTN_REFUND => '申请退款',
        self::BTN_RECEIPT => '确认收货',
        self::BTN_FINISH => '完成订单',
        self::BTN_DELETE => '删除订单',
        self::BTN_CUSTOMER => '联系客服',
        self::BTN_REMAINING => '支付尾款', -->
<script>
	import { orderDetials, getOrder, getAfterOrder, paycancel, receipTOrder, delTOrder, computTOrder } from '@/api/goods.js'
	import { payCreatOrder,  payformOrder } from '@/api/pay.js'
	import  goodsItem from './components/goodsItem.vue'
	export default {
		components:{
			goodsItem
		},
		data() { 
			return {
				id:'',
				goods:[],
				model:{},
				order_status:-1,
				is_pre:''
			}
		},
		onLoad() {
			this.id = this.$Route.query.id
			// console.log(this.id);
			// console.log(this.user);
			this.OrderDetials();
		},
		methods: {
			btnEVent(id,model) {
				console.log(id);
				switch(id)
					{
						case 1:
							// this.$Router.push('/pages/orderDetail/orderDetail?id=' + item.id)
							break;
						case 4:
							 let parms;
							 if(this.order_status == 1) {
								 parms = 1;
							 } else {
								  parms = 2;
							 }
							this.$Router.push('/pages/afterInput/afterInput?id=' + model.id +'&select=' + parms)
							break;
						case 5:			
							this.ReceipTOrder(this.model.id)			
							break;
						case 2:
							payformOrder(this.model.id);
							break;
						case 3:
							this.Paycancel(this.model.id)
							break;
						case 6:
							// console.log('完成订单');
							this.ComputTOrder(this.model.id)
							break;
						  case 7: 
							this.DelTOrder(this.model.id)
							break;
						 case 9: 
							this.topay();
							break;
						case 10:
							payformOrder(this.item.payment_pay.order_id);
							break;	
						case 11:
							this.$Router.push('/pages/afterDetial/afterDetial?id=' + this.model.last_after_sale.id)
							break;
						default:
							break;
					}
			},
			topay() {
				let goods_ids = {}
				// let is_selectGoods = this.goods.filter(item  => item.is_selected  == 1);
				// console.log(is_selectGoods);
				this.goods.forEach((item) => {
					goods_ids[item.goods_id] = item.quantity
				})
				// console.log(item.order_goods);
				// console.log(goods_ids);
				const post_data = {
					student_id:this.model.payment_pay.student_id,
					activity_id:this.model.payment_pay.activity_id,
					goods_ids:JSON.stringify(goods_ids),
					master_order_id:this.model.id
				}
				payCreatOrder(post_data);
				//console.log(post_data);
			},
			async Paycancel(id) {
			   const res = await paycancel({id:id});
			   if(res) {	
				   uni.showToast({
				   	  title:'操作成功',
				   	  icon:'none'
				   })
				   uni.navigateBack();
			   }
			},
			async DelTOrder(id) {
			  const res = await delTOrder({id:id});
			  // console.log(res);
			  if(res) {
				  this.toast('操作成功');
				  uni.navigateBack();
			  }
			},
			async ComputTOrder(id) {
				 const res = await computTOrder({id:id});
				 if(res) {
					 uni.showToast({
					 	title:'操作成功',
						icon:'none'
					 })
					 uni.navigateBack();
				 }
			},
			async  OrderDetials () {
				const { data } = await orderDetials({id:this.id}) 
				if(data) {
					this.goods = data.item.data;
					this.model = data.model;
					this.is_pre = this.model.prepayment_type;
					this.order_status = this.model.show_status;
					// console.log('is_pre',this.is_pre);
					// console.log('order_status',this.order_status);
					// console.log('model',this.model);
					console.log('model',this.model);
					console.log('this.goods',this.goods);
				}
				
			},
			async ReceipTOrder(id) {
				 const res = await receipTOrder({id:id});
				 if(res) {
					 uni.showToast({
						title:'操作成功',
						icon:'none'
					 })
					uni.navigateBack()
				 }
			},
			scrolltolower() {
				
			},
			togleOpen() {
				this.open = !this.open;
			},
			gochangeSchool() {
				uni.navigateTo({
					url:'/pages/changeSchool/changeSchool'
				})
			},
			change(e) {
				this.swiper.current = e.detail.current;
			},
			getTime(timestamp) {
				console.log(timestamp);
				const date = new Date(timestamp * 1000);
				const year = date.getFullYear();
				const month = ('0' + (date.getMonth() + 1)).slice(-2);
				const day = ('0' + date.getDate()).slice(-2);
				const hours = ('0' + date.getHours()).slice(-2);
				const minutes = ('0' + date.getMinutes()).slice(-2);
				const seconds = ('0' + date.getSeconds()).slice(-2);
				const formattedDate = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
				return formattedDate;
			}
		}
	}
</script>

<style lang="scss">
	@import "@/static/css/dls.scss";
	@import "@/static/css/detial.scss";
	.page {
		background-color: #f5f8fa;
		width: 100%;
		height: 100%;
		overflow: hidden;
	}
	
	.red {
		color:#ff4f4f;
	}
	.colorh {
		color:#a6a6a6;
	}
	.pageBox {
		padding-bottom: 130rpx;
		.status {
			height: 102rpx;
			// display: flex;
			padding-top: 14rpx;
			font-size: 36rpx;
			color:#3c84f4;
			font-weight: bold;
			padding-left: 32rpx;
			.red {
				color:#ff4f4f;
			
			}
			
		}
	}
	
	
	.bottomBtn {
		padding-top: 55rpx;
		@include bt-s-1();
	}
	
</style>
